package com.oom;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @Author: tgy
 * @Date: 2020-08-05 10:41
 * Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
 * 	at java.lang.Thread.start0(Native Method)
 * 	at java.lang.Thread.start(Thread.java:717)
 * 	at com.oom.Unable_To_Create_New_Native_Thread.main(Unable_To_Create_New_Native_Thread.java:33)
 */
public class Unable_To_Create_New_Native_Thread {

    public  static void main(String[] args) {

        int index = 0;

        List<Thread> threads = new ArrayList<>();

        while (true){

            Thread thread = new Thread(() -> {

                try {

                    TimeUnit.SECONDS.sleep(Integer.MAX_VALUE);

                }catch (Exception e){

                }
            });

            thread.start();

            threads.add(thread);


            index++;

            System.out.println(index);
        }

    }
}
